package org.zhadoop.stream.cql.executor;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

import org.zhadoop.streaming.expression.ArithmeticExpression;
import org.zhadoop.streaming.expression.ExpressionOperator;
import org.zhadoop.streaming.expression.IExpression;

/**
 * 二元表达式注册
 * 
 * 二元表达式就是诸如： +，-，*，/，<，>之类
 * 
 * @author zwd
 *
 */
public class BinaryExpressionRegistry {
	private static final Map<String, BinaryExpression> BINARYEXPRESSIONS = Collections
			.synchronizedMap(new LinkedHashMap<String, BinaryExpression>());
	static{
		//数学表达式
		registerExpression("+",ExpressionOperator.ADD,ArithmeticExpression.class);
		registerExpression("-",ExpressionOperator.SUBTRACT,ArithmeticExpression.class);
		registerExpression("*", ExpressionOperator.MULTIPLY, ArithmeticExpression.class);
		registerExpression("/", ExpressionOperator.DIVIDE, ArithmeticExpression.class);
		registerExpression("%", ExpressionOperator.MOD, ArithmeticExpression.class);
	}

	/**
	 * 注册表达式
	 */
	public static void registerExpression(String describe, ExpressionOperator type,
			Class<? extends IExpression> expression) {
		BINARYEXPRESSIONS.put(describe, new BinaryExpression(describe, type, expression));
	}
	
	public static BinaryExpression getBinaryExpressionByName(String desc){
		return BINARYEXPRESSIONS.get(desc);
	}

}
